Skip to content

refactor(core): TimeProvider migration Phase 2 — VMs, Mvc, TokenService#708

Merged
cct08311github merged 1 commit intodotnet10from
refactor/timeprovider-phase2-706
Mar 21, 2026
Merged

refactor(core): TimeProvider migration Phase 2 — VMs, Mvc, TokenService#708
cct08311github merged 1 commit intodotnet10from
refactor/timeprovider-phase2-706

Conversation

@cct08311github
Copy link
Copy Markdown
Owner

Summary

  • Migrate remaining DateTime.Now/UtcNow to TimeProvider across 9 files (Core VMs, Mvc controllers/filters, TokenService)
  • TokenService: constructor-injected TimeProvider with optional param (backwards compatible)
  • Null-safe fallbacks for BaseTemplateVM and FrameworkFilter where Wtm may be null

Key insight discovered

DateTimeOffset.DateTime returns DateTimeKind.Unspecified, causing JWT library to misinterpret UTC times as local. Fixed by using .UtcDateTime for all UTC contexts.

Skipped (by design)

  • .cshtml cache-bust (DateTime.Now.Ticks) — display only
  • TypeExtension random data generation — not business logic
  • Codegen .txt templates — generated code style
  • Property initializers (RefreshTokenEntity, ChangeLog) — no DI at construction
  • Static BuildCsv — display timestamp
  • JWT LifetimeValidator lambda — security validation should use system time

Test plan

  • dotnet build -c Release — 0 errors
  • Core tests: 1098 passed
  • Admin tests: 75 passed
  • ETL tests: 174 passed (17 skipped)
  • Total: 1347 passed, 0 failed

Closes #706

🤖 Generated with Claude Code

…— VMs, Mvc, TokenService)

Replace direct DateTime.Now/UtcNow calls with Wtm.TimeProvider or injected
TimeProvider across 9 files:

- Core VMs: BaseBatchVM, BaseImportVM, BasePagedListVM, BaseTemplateVM
- Mvc: _FrameworkController, FrameworkFilter, _AnalysisController, FileExtension
- Auth: TokenService (constructor-injected TimeProvider)

Key decisions:
- TokenService: inject TimeProvider via optional ctor param (defaults to System)
- FrameworkFilter: null-safe fallback (ctrl.Wtm?.TimeProvider ?? DateTime.Now)
- BaseTemplateVM: null-safe (Wtm?.TimeProvider ?? TimeProvider.System) since
  Template instance may not have Wtm assigned
- Use .UtcDateTime (not .DateTime) for UTC contexts to preserve DateTimeKind.Utc
- Skip: .cshtml cache-bust, TypeExtension random data, codegen templates,
  property initializers, static BuildCsv, JWT LifetimeValidator

Closes #706

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cct08311github cct08311github merged commit b411701 into dotnet10 Mar 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(core): [P0-06b] TimeProvider migration — remaining 42 occurrences

1 participant